/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Connection.CheckInfo;
import Bussiness.DepartmentDAO;
import Bussiness.EmployeeDAO;
import Bussiness.LocationDAO;
import Bussiness.ProjectDAO;
import Connection.DBUtil;
import Connection.Employee;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author SONY
 */
public class AddEmployee extends javax.swing.JFrame {
    /**
     * Creates new form AddEmployee
     */
    private Employee objEmployee1 = null;
    private String employeeID = null;
    DefaultTableModel model;
    public AddEmployee() {
        initComponents();
        LoadData(); 
        try {
            loadDepartment();
        } catch (Exception ex) {
            Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            loadLocation();
        } catch (Exception ex) {
            Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            loadProject();
        } catch (Exception ex) {
            Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    private void LoadData() {
        String SQL;
        DBUtil objDBUtil = new DBUtil();
        Connection conn = objDBUtil.connect();
        model =(DefaultTableModel)tbBang.getModel();
            try
            {
                SQL = "SELECT * FROM Employee";
                Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
                ResultSet rs = stmt.executeQuery(SQL);
                while(rs.next())
                {
                    Vector v = new Vector();
                    v.add(rs.getString(1));
                    v.add(rs.getString(2));
                    v.add(rs.getString(3));
                    v.add(rs.getBoolean(4));
                    v.add(rs.getString(5));
                    v.add(rs.getString(6));
                    v.add(rs.getString(7));
                    v.add(rs.getString(8));
                    v.add(rs.getString(9));
                    v.add(rs.getString(10));
                    v.add(rs.getString(11));
                    v.add(rs.getString(12));
                    v.add(rs.getString(13));
                    model.addRow(v);
                }
                tbBang.setModel(model);
                rs.close();
                stmt.close();
            }
            catch (SQLException ex) 
            {
                Logger.getLogger(AddProject.class.getName()).log(Level.SEVERE, null, ex);
            } 
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtStt = new javax.swing.JTextField();
        txtID = new javax.swing.JTextField();
        txtName = new javax.swing.JTextField();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        txtPhone = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jpwConfirm = new javax.swing.JPasswordField();
        jLabel11 = new javax.swing.JLabel();
        jpwPassword = new javax.swing.JPasswordField();
        jLabel12 = new javax.swing.JLabel();
        txtWork = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cbLocation = new javax.swing.JComboBox();
        cbDepartment = new javax.swing.JComboBox();
        cbProject = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jDateDayOfBirth = new com.toedter.calendar.JDateChooser();
        jLabel16 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbBang = new javax.swing.JTable();
        btnAdd = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1324, 738));
        getContentPane().setLayout(null);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Admin", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 102, 0)));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/add_user.png"))); // NOI18N
        jLabel1.setText("ADD EMPLOYEE");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(358, 358, 358)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(530, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(0, 13, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2);
        jPanel2.setBounds(10, 0, 1280, 100);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "New Employee", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 102, 0)));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("STT");

        txtStt.setEnabled(false);

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Male");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Female");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Email");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Password");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Confim Password");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Work Experience");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Current Location");

        cbLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbLocationActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Current Department");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("Current Project");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel16.setText("Employee ID");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Employee Name");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Gender");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Day Of Birth");

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel18.setText("Phone Number");

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel19.setText("Address");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19)
                            .addComponent(jLabel12)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel13)
                            .addComponent(jLabel15)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jLabel17))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel14)))
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtAddress)
                        .addComponent(txtPhone)
                        .addComponent(jDateDayOfBirth, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                        .addComponent(txtWork)
                        .addComponent(txtEmail)
                        .addComponent(jpwPassword, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jpwConfirm)
                        .addComponent(cbLocation, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cbProject, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStt, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jRadioButton1)
                        .addGap(43, 43, 43)
                        .addComponent(jRadioButton2)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtStt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel4)
                        .addGap(6, 6, 6))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jRadioButton2, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jDateDayOfBirth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtWork, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jpwPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jpwConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbProject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addComponent(jLabel17))
        );

        tbBang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "EmployeeID", "EmployeeName", "Gender", "DayOfBirth", "Phone", "Address", "Email", "Password", "Work Ex", "LocationID", "ProjectID", "DepartmentID"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tbBang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbBangMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbBang);

        btnAdd.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/16x16/add.png"))); // NOI18N
        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnClear.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnClear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/16x16/refresh.png"))); // NOI18N
        btnClear.setText("Clear");
        btnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClearActionPerformed(evt);
            }
        });

        btnCancel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/16x16/block.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 840, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnClear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnClear)
                    .addComponent(btnAdd))
                .addContainerGap(130, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel3);
        jPanel3.setBounds(10, 100, 1280, 600);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public void insertEmployee() throws SQLException{
        try{
        objEmployee1 = new Employee();
        objEmployee1.setEmployeeID(txtID.getText());
        objEmployee1.setEmployeeName(txtName.getText());
        if (jRadioButton1.isSelected()) {
            objEmployee1.setGender(true);
        } else{
            objEmployee1.setGender(false);
        }
        objEmployee1.setDayOfBirth(jDateDayOfBirth.getDate());
        objEmployee1.setPhone(txtPhone.getText());
        objEmployee1.setAddress(txtAddress.getText());
        objEmployee1.setEmail(txtEmail.getText());
        objEmployee1.setPassword(String.valueOf(jpwConfirm.getPassword()));
        objEmployee1.setWorkExperience(Integer.parseInt(txtWork.getText()));
        objEmployee1.setLocationID(LocationDAO.getLocationID((String) cbLocation.getSelectedItem()));
        objEmployee1.setDepartmentID(DepartmentDAO.getDepartmentID((String) cbDepartment.getSelectedItem()));
        objEmployee1.setProjectID(ProjectDAO.getProjectID((String) cbProject.getSelectedItem()));
        EmployeeDAO.insertEmployeeToDB(objEmployee1);
        JOptionPane.showMessageDialog(null, "Add Employee Successfull");
        } catch(Exception ex){
            JOptionPane.showMessageDialog(null, "Don't Add, Employee ID By Duplicate");
        }
    }
    
    public void updateEmployee() throws SQLException{
        try{
        //String EmployeeID = tbBang.getValueAt(tbBang.getSelectedRow(),1).toString();
        objEmployee1 = new Employee();
        objEmployee1.setEmployeeID(txtID.getText());
        objEmployee1.setEmployeeName(txtName.getText());
        if (jRadioButton1.isSelected()) {
            objEmployee1.setGender(true);
        } else{
            objEmployee1.setGender(false);
        }
        objEmployee1.setDayOfBirth(jDateDayOfBirth.getDate());
        objEmployee1.setPhone(txtPhone.getText());
        objEmployee1.setAddress(txtAddress.getText());
        objEmployee1.setEmail(txtEmail.getText());
        objEmployee1.setPassword(String.valueOf(jpwConfirm.getPassword()));
        objEmployee1.setWorkExperience(Integer.parseInt(txtWork.getText()));
        objEmployee1.setLocationID(LocationDAO.getLocationID((String) cbLocation.getSelectedItem()));
        objEmployee1.setDepartmentID(DepartmentDAO.getDepartmentID((String) cbDepartment.getSelectedItem()));
        objEmployee1.setProjectID(ProjectDAO.getProjectID((String) cbProject.getSelectedItem()));
        employeeID = objEmployee1.getEmployeeID();
        EmployeeDAO.upDateEmployee(objEmployee1, employeeID);
        
        } catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public void clear(){
        txtID.setText("");
        txtName.setText("");
        //jRadioButton2.setSelected(false); 
        //jRadioButton2.setSelected(false);
        //jRadioButton1.setSelected(true);
        //jRadioButton2.setSelected(true);
        jDateDayOfBirth.setDate(null);
        txtPhone.setText("");
        txtAddress.setText("");
        txtWork.setText("");
        txtEmail.setText("");
        jpwPassword.setText("");
        jpwConfirm.setText("");
        cbLocation.setSelectedIndex(0);
        cbDepartment.setSelectedIndex(0);
        cbProject.setSelectedIndex(0);
    }
    
    public void loadLocation() throws Exception
    {
        Vector v = new Vector();
        v = LocationDAO.getComboBoxLocationFromDB();
        cbLocation.setModel(new DefaultComboBoxModel(v));
    } 
    
    public void loadDepartment() throws Exception
    {
        Vector v = new Vector();
        v = DepartmentDAO.getComboBoxDepartmentFromDB();
        cbDepartment.setModel(new DefaultComboBoxModel(v));
    } 
    public void loadProject() throws Exception
    {
        Vector v = new Vector();
        v = ProjectDAO.getComboBoxProjectFromDB();
        cbProject.setModel(new DefaultComboBoxModel(v));
    } 
    
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
            int kq=JOptionPane.showConfirmDialog(this, "Are You Want To Exit","Messager",JOptionPane.YES_NO_OPTION);
                if(kq==JOptionPane.YES_OPTION){
                    this.dispose();
                }
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        try {
            if(!CheckInfo.checkEmpty(txtID.getText())){
                JOptionPane.showMessageDialog(null, "You Nead Enter For EmployeeID Field");
                txtID.requestFocus();
            } else if (!CheckInfo.checkEmpty(txtName.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For EmployeeName Field");
                txtName.requestFocus();
            }else if (jDateDayOfBirth.getDate() == null) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For DayOfBirth Field");
                jDateDayOfBirth.requestFocus();
            }else if (!CheckInfo.checkEmpty(txtPhone.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Phone Field");
                txtPhone.requestFocus();
            }else if (!CheckInfo.checkEmpty(txtAddress.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Address Field");
                txtAddress.requestFocus();
            }else if (!CheckInfo.checkEmpty(txtWork.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Work Experience Field");
                txtWork.requestFocus();
            }else if (!CheckInfo.checkEmpty(txtEmail.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Email Field");
                txtEmail.requestFocus();
            }else if (!CheckInfo.checkEmail(txtEmail.getText())) {
                JOptionPane.showMessageDialog(null, "You Nead Enter Format Email Field");
                txtEmail.setText("");
                txtEmail.requestFocus();
            }else if (!CheckInfo.checkEmpty(String.valueOf(jpwPassword.getPassword()))) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Password Field");
                jpwPassword.requestFocus();
            }else if (!CheckInfo.checkEmpty(String.valueOf(jpwConfirm.getPassword()))) {
                JOptionPane.showMessageDialog(null, "You Nead Enter For Confirm Password Field");
                jpwConfirm.requestFocus();
            } else if (jpwConfirm.equals(jpwPassword)) {
                JOptionPane.showMessageDialog(null, "You Nead Enter Excally Password Field");
                jpwConfirm.setText("");
                jpwPassword.setText("");
                jpwConfirm.requestFocus();
            } else if (cbLocation.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "You Nead Choice Location Field");
            } else if (cbDepartment.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "You Nead Choice Department Field");
            } else if (cbProject.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "You Nead Choice Project Field");
            } else{
                insertEmployee();
                //JOptionPane.showMessageDialog(null, "Them Moi thanh Cong");
                clear();
            }
        } catch (SQLException ex) {
            Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        while(model.getRowCount()>0)
        model.removeRow(0);
        LoadData();

    }//GEN-LAST:event_btnAddActionPerformed

    private void cbLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbLocationActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbLocationActionPerformed

    private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_btnClearActionPerformed

    private void tbBangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBangMouseClicked
        //TODO add your handling code here:
        txtStt.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 0).toString());
        txtID.setText((String) tbBang.getValueAt(tbBang.getSelectedRow(), 1));
        txtName.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 2).toString());
        if (Boolean.valueOf(tbBang.getValueAt(tbBang.getSelectedRow(), 3).toString()) == true) {
            jRadioButton1.setSelected(true);
        } else{
            jRadioButton2.setSelected(true);
        }
        //String date = tbBang.getValueAt(tbBang.ge, WIDTH)
        //Date date = Time.valueOf(st);
        //Date todayDate = new Date(System.currentTimeMillis());
        //SimpleDateFormat dayFormat = new SimpleDateFormat("dd/MM/yyyy");
        //String todayString = Time.valueOf(dayFormat.format(tbBang.getValueAt(tbBang.getSelectedRow(), 4).toString()));
        //jDateDayOfBirth.setDat
        txtPhone.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 5).toString());
        txtAddress.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 6).toString());
        txtWork.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 9).toString());
        txtEmail.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 7).toString());
        jpwPassword.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 8).toString());
        jpwConfirm.setText(tbBang.getValueAt(tbBang.getSelectedRow(), 8).toString());
        try {
            cbLocation.setSelectedItem(LocationDAO.getLocationName(tbBang.getValueAt(tbBang.getSelectedRow(), 10).toString()));
            cbDepartment.setSelectedItem(DepartmentDAO.getDepartmentName(tbBang.getValueAt(tbBang.getSelectedRow(), 11).toString()));
            cbProject.setSelectedItem(ProjectDAO.getProjectName(tbBang.getValueAt(tbBang.getSelectedRow(), 12).toString()));
        } catch (SQLException ex) {
            Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_tbBangMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddEmployee.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddEmployee().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnClear;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbDepartment;
    private javax.swing.JComboBox cbLocation;
    private javax.swing.JComboBox cbProject;
    private com.toedter.calendar.JDateChooser jDateDayOfBirth;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPasswordField jpwConfirm;
    private javax.swing.JPasswordField jpwPassword;
    private javax.swing.JTable tbBang;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtStt;
    private javax.swing.JTextField txtWork;
    // End of variables declaration//GEN-END:variables
}
